'icon-name': GObject.ParamSpec.string('icon-name', '', '',
GObject.ParamFlags.READWRITE,
''),
+ 'label': GObject.ParamSpec.string('label', '', '',
+ GObject.ParamFlags.READWRITE,
+ ''),
},
Signals: {
'activation-failed': {},
this._itemBinding = new GObject.BindingGroup();
this._itemBinding.bind('icon-name',
this, 'icon-name', GObject.BindingFlags.DEFAULT);
+ this._itemBinding.bind_full('name',
+ this, 'label', GObject.BindingFlags.DEFAULT,
+ (bind, source) => [true, this._transformLabel(source)],
+ null);
}
setClient(client) {
throw new GObject.NotImplementedError();
}
+ // transform function for property binding:
+ // Ignore the provided label if there are multiple active
+ // items, and replace it with something like "VPN (2)"
+ _transformLabel(source) {
+ const nActive = this.checked
+ ? [...this._getActiveItems()].length
+ : 0;
+ if (nActive > 1)
+ return `${this._getDefaultName()} (${nActive})`;
+ return source;
+ }
+
_updateItemsVisibility() {
[...this._itemSorter.itemsByMru()].forEach(
(item, i) => (item.visible = i < MAX_VISIBLE_NETWORKS));
}
+ _itemActiveChanged() {
+ // force an update in case we changed
+ // from or to multiple active items
+ this._itemBinding.source?.notify('name');
+ this._sync();
+ }
+
_updateChecked() {
const [firstActive] = this._getActiveItems();
this.checked = !!firstActive;
`${this} already has an item for ${key}`);
item.connectObject(
- 'notify::is-active', () => this._sync(),
+ 'notify::is-active', () => this._itemActiveChanged(),
'notify::name', () => this._resortItem(item),
'destroy', () => this._removeItem(key),
this);
this);
}
+ _getDefaultName() {
+ return _('VPN');
+ }
+
_loadInitialItems() {
const connections = this._client.get_connections();
for (const conn of connections)
}, this);
}
+ _getDefaultName() {
+ const [dev] = this._nmDevices;
+ const [name] = NM.Device.disambiguate_names([dev]);
+ return name;
+ }
+
_loadInitialItems() {
const devices = this._client.get_devices();
for (const dev of devices)